class Content {
  int? id;
  String picture;
  String description;
  int userId;
  int topicId; // 新增topicId字段
  DateTime? publishedAt; // 新增发布时间字段

  Content({
    this.id,
    required this.picture,
    required this.description,
    required this.userId,
    required this.topicId,
    this.publishedAt,
  });

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'picture': picture,
      'description': description,
      'userId': userId,
      'topicId': topicId,
      'publishedAt': publishedAt?.millisecondsSinceEpoch,
    };
  }

  factory Content.fromMap(Map<String, dynamic> map) {
    return Content(
      id: map['id'],
      picture: map['picture'],
      description: map['description'],
      userId: map['userId'],
      topicId: map['topicId'],
      publishedAt: map['publishedAt'] != null
          ? DateTime.fromMillisecondsSinceEpoch(map['publishedAt'])
          : null,
    );
  }

  Content copyWith({
    int? id,
    String? picture,
    String? description,
    int? userId,
    int? topicId,
    DateTime? publishedAt,
  }) {
    return Content(
      id: id ?? this.id,
      picture: picture ?? this.picture,
      description: description ?? this.description,
      userId: userId ?? this.userId,
      topicId: topicId ?? this.topicId,
      publishedAt: publishedAt ?? this.publishedAt,
    );
  }
}
